package com.unknowpupil.sell.config.wx;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @Classname: WechatMpConfig
 * @Author: <a> w10g </a>
 * @CreateDate: Create in 2019/12/31 15:31
 * @Description:
 * @Version: 1.0
 */
@Component
public class WechatMpConfig {
    @Autowired
    WxMpProperties wxMpProperties;

    @Bean
    public WxMpService wxMpService() {
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
        return wxMpService;
    }

    @Bean
    public WxMpConfigStorage wxMpConfigStorage() {
        WxMpConfigStorage wxMpConfigStorage = new WxMpDefaultConfigImpl();
        ((WxMpDefaultConfigImpl) wxMpConfigStorage).setAppId(wxMpProperties.getAppId());
        ((WxMpDefaultConfigImpl) wxMpConfigStorage).setSecret(wxMpProperties.getSecret());
        return wxMpConfigStorage;
    }
}
